import { useEffect } from 'react';
import { useDispatch, useSelector } from 'react-redux';
import { getNewsByIdAction } from '../store/action/news';
export default function News() {
  const dispatch = useDispatch();
  const { currentId } = useSelector((state) => state.channel);
  useEffect(() => {
    dispatch(getNewsByIdAction(currentId));
  }, [dispatch, currentId]);

  const { newsList } = useSelector((state) => state.news);

  return (
    <div className="list">
      {newsList.map((item) => {
        return (
          <div key={item.art_id} className="article_item">
            <h3 className="van-ellipsis">{item.title}</h3>
            <div className="img_box">
              {item.cover.images?.map((url) => {
                return <img src={url} className="w100" alt="" />;
              })}
            </div>
            <div className="info_box">
              <span>{item.aut_name}</span>
              <span>{item.comm_count}评论</span>
              <span>{item.pubdate}</span>
            </div>
          </div>
        );
      })}
    </div>
  );
}
